package com.gezhi.clsserver.clsmag.controller;

import com.gezhi.clsserver.bean.ClassBean;
import com.gezhi.clsserver.clsmag.service.IClassService;
import com.gezhi.clsserver.dto.ResultData;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 班级控制器
 *
 * @author AWG
 */
@RequestMapping(value = "/cls")
@RestController
public class ClassController {

	@Resource
	private IClassService classServiceImpl;

	/**
	 * 新增班级
	 * @param classBean 班级对象
	 */
	@PostMapping("/list")
	public ResultData saveMember(ClassBean classBean){
		classServiceImpl.saveClass(classBean);
		ResultData resultData = new ResultData();
		resultData.setCode("0");
		resultData.setMsg("操作成功");
		return resultData;
	}

	/**
	 * 修改班级
	 * @param classBean 班级对象
	 */
	@PutMapping("/{id}")
	public ResultData updateMember(@PathVariable("id") Integer id, ClassBean classBean){
		classBean.setId(id);
		classServiceImpl.updateClass(classBean);
		ResultData resultData = new ResultData();
		resultData.setCode("0");
		resultData.setMsg("操作成功");
		return resultData;
	}

	/**
	 * 删除班级
	 * @param classBean 班级对象
	 */
	@DeleteMapping("/{id}")
	public ResultData deleteMember(@PathVariable("id") Integer id, ClassBean classBean){
		classBean.setId(id);
		classServiceImpl.deleteClass(classBean);
		ResultData resultData = new ResultData();
		resultData.setCode("0");
		resultData.setMsg("操作成功");
		return resultData;
	}

	/**
	 * 根据班级ID查询班级
	 * @param id 班级ID
	 */
	@GetMapping("/{id}")
	public ResultData getMemberById(@PathVariable("id") Integer id){
		ClassBean classBean = classServiceImpl.getClassById(id);
		ResultData resultData = new ResultData();
		resultData.setCode("0");
		resultData.setMsg("操作成功");
		resultData.setData(classBean);
		return resultData;
	}

	/**
	 * 查询所有的班级
	 * @return 所有的班级组成的List集合
	 */
	@GetMapping("/list")
	public ResultData findAllClass(){
		ResultData resultData = new ResultData();
		resultData.setCode("0");
		resultData.setMsg("操作成功");
		resultData.setData(classServiceImpl.findAllClass());
		return resultData;
	}


}
